rmgr's wiki

> / > general > interesting-links

XDG user directories - ArchWiki (wiki.archlinux.org)

https://wiki.archlinux.org/title/XDG_user_directories

Content

[](https://archlinux.org/){#logo}

- #anb-home}

- #anb-packages}

- #anb-forums}

- #anb-wiki}

- #anb-gitlab}

- #anb-security}

- #anb-aur}

- #anb-download}

[Jump to content](#bodyContent){.mw-jump-link}

Main menu

Main menu

move to sidebar

hide

Navigation

- [Main page]{#n-mainpage-description}

- [Table of contents]{#n-Table-of-contents}

- [Getting involved]{#n-portal}

- [Wiki news]{#n-currentevents}

- [Random page]{#n-randompage}

Interaction

- [Help]{#n-help}

- [Contributing]{#n-Contributing}

- [Recent changes]{#n-recentchanges}

- [Recent talks]{#n-Recent-talks}

- [New pages]{#n-newpages}

- [Statistics]{#n-Statistics}

- [Requests]{#n-Requests}

Search

Search

```{=html}

!-- --

```

Appearance

```{=html}

!-- --

```

- [Create account]{#pt-createaccount-2}

- [Log in]{#pt-login-2}

Personal tools

- [Create account]{#pt-createaccount}

- [Log in]{#pt-login}

ontents {#contents .vector-pinnable-header-label}

move to sidebar

hide

- #){.vector-toc-link}]{#toc-mw-content-text}#toc-mw-content-text}

Beginning

- #Installation){.vector-toc-link}]{#toc-Installation}#toc-Installation}

1

Installation

- #Creating_default_directories){.vector-toc-link}]{#toc-Creating_default_directories}#toc-Creating_default_directories}

2

Creating default directories

- #Creating_custom_directories){.vector-toc-link}]{#toc-Creating_custom_directories}#toc-Creating_custom_directories}

3

Creating custom directories

- #Querying_configured_directories){.vector-toc-link}]{#toc-Querying_configured_directories}#toc-Querying_configured_directories}

4

Querying configured directories

Toggle the table of contents

XDG user directories

5 languages

- Català

- 日本語

- Português

- Русский

- 中文(简体)

```{=html}

!-- --

```

- [Page]{#ca-nstab-main}

- [Discussion]{#ca-talk}

English

```{=html}

!-- --

```

- [Read]{#ca-view}

- [View source]{#ca-viewsource}

- [View history]{#ca-history}

Tools

Tools

move to sidebar

hide

Actions

- [Read]{#ca-more-view}

- [View source]{#ca-more-viewsource}

- [View history]{#ca-more-history}

General

- [What links here]{#t-whatlinkshere}

- [Related changes]{#t-recentchangeslinked}

- [Special pages]{#t-specialpages}

- [Printable version]{#t-print}

- [Permanent link]{#t-permalink}

- [Page information]{#t-info}

Appearance

move to sidebar

hide

From ArchWiki

Related articles

- [Environment variables](/title/Environment_variables "Environment variables")

- [Default applications](/title/Default_applications "Default applications")

- [XDG Base Directory support](/title/XDG_Base_Directory_support "XDG Base Directory support"){.mw-redirect}

- [xdg-menu](/title/Xdg-menu "Xdg-menu")

From [freedesktop.org](https://www.freedesktop.org/wiki/Software/xdg-user-dirs/){.external .text rel="nofollow"}:

The way it works is that

[xdg-user-dirs-update(1)](https://man.archlinux.org/man/xdg-user-dirs-update.1){.external .text rel="nofollow"} is run very early in the login phase. This program reads a configuration file, and a set of default directories. It then creates localized versions of these directories in the user home directory and sets up a configuration file in `$XDG_CONFIG_HOME/user-dirs.dirs` (`XDG_CONFIG_HOME` defaults to `~/.config`) that applications can read to find these directories.

Most [file managers](/title/File_manager "File manager"){.mw-redirect} indicate XDG user directories with special icons.

Installation

[Install](/title/Install "Install"){.mw-redirect}

[xdg-user-dirs](https://archlinux.org/packages/?name=xdg-user-dirs){.external .text rel="nofollow"}.

Creating default directories

Creating a full suite of localized default user directories within the `$HOME` directory can be done automatically by running:

$ xdg-user-dirs-update

When executed, it will also automatically:

- Create a local `~/.config/user-dirs.dirs` configuration file: used by applications to find and use home directories specific to an account.

- Create a local `~/.config/user-dirs.locale` configuration file: used to set the language according to the locale in use.

The user service `xdg-user-dirs-update.service` will also be installed and enabled by default, in order to keep your directories up to date by running this command at the beginning of each login session.

Creating custom directories

Both the local `~/.config/user-dirs.dirs` and global `/etc/xdg/user-dirs.defaults` configuration files use the following environmental variable format to point to user directories: `XDG_DIRNAME_DIR="$HOME/directory_name"` An example configuration file may likely look like this (these are all the template directories):

``` {style="margin-bottom: 0; border-bottom:none; padding-bottom:0.8em;"}

~/.config/user-dirs.dirs

```

``` {style="margin-top: 0; border-top-style:dashed; padding-top: 0.8em;"}

XDG_DESKTOP_DIR="$HOME/Desktop"

XDG_DOCUMENTS_DIR="$HOME/Documents"

XDG_DOWNLOAD_DIR="$HOME/Downloads"

XDG_MUSIC_DIR="$HOME/Music"

XDG_PICTURES_DIR="$HOME/Pictures"

XDG_PUBLICSHARE_DIR="$HOME/Public"

XDG_TEMPLATES_DIR="$HOME/Templates"

XDG_VIDEOS_DIR="$HOME/Videos"

```

As

[xdg-user-dirs](https://archlinux.org/packages/?name=xdg-user-dirs){.external .text rel="nofollow"} will source the local configuration file to point to the appropriate user directories, it is therefore possible to specify custom folders. For example, if a custom folder for the `XDG_DOWNLOAD_DIR` variable has named `$HOME/Internet` in `~/.config/user-dirs.dirs` any application that uses this variable will use this directory.

Alternatively, it is also possible to specify custom folders using the command line. For example, the following command will produce the same results as the above configuration file edit:

$ xdg-user-dirs-update --set DOWNLOAD ~/Internet

Querying configured directories

Once set, any user directory can be viewed with

[xdg-user-dirs](https://archlinux.org/packages/?name=xdg-user-dirs){.external .text rel="nofollow"}. For example, the following command will show the location of the `Templates` directory, which of course corresponds to the `XDG_TEMPLATES_DIR` variable in the local configuration file:

$ xdg-user-dir TEMPLATES

eval echo \${XDG_${1}_DIR:-$HOME}

This means that `xdg-user-dir` facilitates arbitrary code execution from unsanitized input. Unless this unsafe implementation is fixed upstream, `xdg-user-dir` should only ever be used with a hard-coded or strictly audited argument.

Retrieved from \"[https://wiki.archlinux.org/index.php?title=XDG_user_directories&oldid=819357](https://wiki.archlinux.org/index.php?title=XDG_user_directories&oldid=819357){dir="ltr"}\"

[Category](/title/Special:Categories "Special:Categories"):

- [Freedesktop.org](/title/Category:Freedesktop.org "Category:Freedesktop.org")

```{=html}

!-- --

```

- [This page was last edited on 21 October 2024, at 05:24.]{#footer-info-lastmod}

- [Content is available under [GNU Free Documentation License 1.3 or later](https://www.gnu.org/copyleft/fdl.html){.external rel="nofollow"} unless otherwise noted.]{#footer-info-copyright}

```{=html}

!-- --

```

- #footer-places-privacy}

- #footer-places-about}

- #footer-places-disclaimers}

- #footer-places-archwiki-code-of-conduct}

- #footer-places-archwiki-terms-of-service}

```{=html}

!-- --

```

- GNU Free Documentation License 1.3 or later#footer-copyrightico}

- [{width="88" height="31" loading="lazy"}]{#footer-poweredbyico}

```{=html}

!-- --

```